#include <GameEngine/Gameplay/dice.h>

#ifdef _DEBUG
#include <assert.h>
#endif


#ifdef GAMEENGINE_NAMESPACES
namespace GameEngine {
#endif

MTRand Dice::rand_;


//! Constructor
/*!
 @param faces The number of faces of the dice. This number should always be
              strictly superior to 0
 @note In debug mode, we assert that the number of faces of the dice is at
       least 1. No checking is performed in release mode.
 */
Dice::Dice(unsigned int faces) : faces_(faces) {
#ifdef _DEBUG
	assert(faces_>0);
#endif
}

//! Copy constructor
/*!
 @param rhs The dice to copy
 */
Dice::Dice(const Dice& rhs) : faces_(rhs.faces_) {}

//! Destructor
Dice::~Dice() {}

//! Assignment operator
/*!
 @param rhs The dice to copy
 */
Dice& Dice::operator=(const Dice& rhs) {
	if ( &rhs != this ) {
		faces_ = rhs.faces_;
	}
	return *this;
}

//! Accessor to the number of faces of the dice (read only)
/*!
 @return The number of faces of the dice
 */
unsigned int Dice::faces() const {
	return faces_;
}

//! Change the number of faces of the dice
/*!
 @param faces The new number of faces of the dice. This number should always
              be strictly superior to 0
 @note In debug mode, we assert that the number of faces of the dice is at
       least 1. No checking is performed in release mode.
 */
void Dice::set_faces(unsigned int faces) {
	faces_ = faces;
#ifdef _DEBUG
	assert(faces_>0);
#endif
}

//! Roll the dice and return the result
/*!
 @return The face on which the dice stopped. Face is comprised between
         1 and the number of faces of the dice
 */
unsigned int Dice::roll_dice() const {
	return ( 1 + (unsigned int)rand_.randInt(faces_-1) );
}

//! Create a four-sided dice
/*!
 @return A four-sided dice
 */
Dice Dice::dice4() {
	return Dice(4);
}

//! Create a six-sided dice
/*!
 @return A six-sided dice
 */
Dice Dice::dice6() {
	return Dice(6);
}

//! Create an eight-sided dice
/*!
 @return An eight-sided dice
 */
Dice Dice::dice8() {
	return Dice(8);
}

//! Create a ten-sided dice
/*!
 @return A ten-sided dice
 */
Dice Dice::dice10() {
	return Dice(10);
}

//! Create a twelve-sided dice
/*!
 @return A twelve-sided dice
 */
Dice Dice::dice12() {
	return Dice(12);
}

//! Create a twenty-sided dice
/*!
 @return A twenty-sided dice
 */
Dice Dice::dice20() {
	return Dice(20);
}



#ifdef GAMEENGINE_NAMESPACES
} // namespace GameEngine
#endif
